package main


type Block struct {
	size  int
	start int
}

type Allocator struct {
	blocks []int
}

func Constructor(n int) Allocator {
	blocks := make([]int, n)
	return Allocator{
		blocks: blocks,
	}
}

func (this *Allocator) Allocate(size int, mID int) int {
	count := 0
	start := 0
	for i, owner := range this.blocks {
		if owner == 0 {
			count++
			if count == size {
				for j := 0; j < count; j++ {
					this.blocks[start + j] = mID
				}
				return start
			}
		} else {
			count = 0
			start = i + 1
		}
	}
	return -1
}

func (this *Allocator) FreeMemory(mID int) int {
	count := 0
	for i, owner := range this.blocks {
		if owner == mID {
			this.blocks[i] = 0
			count++
		}
	}
	return count
}

func main() {
	a := Constructor(10)
	println(a.Allocate(1, 1))
	println(a.Allocate(1, 2))
	println(a.Allocate(1, 3))
	println(a.FreeMemory(2))
	println(a.Allocate(3, 4))
	println(a.Allocate(1, 1))

}